<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Permission extends Model
{
    
    protected $table = 'permission';

    protected $primaryKey = 'permission_id';

    public $timestamps = false;

    protected $appends = ['permission_status_format', 'operation'];

    public function getPermissionStatusFormatAttribute()
    {
        $result = $this->permission_status ? '<span class="clr-r">显示</span>' : '隐藏';
        return $result;
    }

    public function getOperationAttribute()
    {
        $this->permission_name = trim($this->permission_name);
        $html = "<i class='fa fa-eyedropper' title='设置权限名称' onclick=layInput(0,'权限名称','/admin/permission/editname','{$this->permission_id}','{$this->permission_name}')></i>";

        if ($this->permission_status) {
            $html .= "<i class='fa fa-level-down ml-15' onclick=layChangeStatus('/admin/permission/status/{$this->permission_id}/0','隐藏')></i>";
        } else {
            $html .= "<i class='fa fa-level-up ml-15' onclick=layChangeStatus('/admin/permission/status/{$this->permission_id}/1','显示')></i>";
        }
        $this->adminremark = trim($this->adminremark);
        $html .= "<i class='fa fa-edit ml-15' title='备注' onclick=layInput(2,'备注','/admin/permission/remark','{$this->permission_id}','{$this->adminremark}')></i>";
        return $html;
    }
}
